package com.ruoyi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.mapper.PostbarCollectMapper;
import com.ruoyi.pojo.PostbarCollect;
import com.ruoyi.service.PostbarCollectService;
import com.ruoyi.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/postbarcollect")
@CrossOrigin
public class PostBarCollectController {

    @Autowired
    private PostbarCollectService postbarCollectService;

    @PostMapping("/add")
    public R<String> add(@RequestBody PostbarCollect postbarCollect){
        int i = postbarCollectService.add(postbarCollect);
        if (i > 0) {
            return R.success("添加成功");
        }else{
            return R.error("添加失败");
        }
    }

    @PostMapping("/remove")
    public R<String> remove(@RequestBody PostbarCollect postbarCollect){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("postbarid",postbarCollect.getPostbarid());
        wrapper.eq("userid",postbarCollect.getUserid());
        boolean remove = postbarCollectService.remove(wrapper);
        if (remove) {
            return R.success("删除成功");
        }else{
            return R.error("删除失败");
        }
    }

    @GetMapping("/one")
    public R<PostbarCollect> one(PostbarCollect postbarCollect){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("postbarid",postbarCollect.getPostbarid());
        wrapper.eq("userid",postbarCollect.getUserid());
        PostbarCollect one = postbarCollectService.getOne(wrapper);
        return R.success(one);
    }
}
